/*********************************************************
          File Name:13.1.cpp
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Wed 16 Sep 2015 08:21:51 PM CST
**********************************************************/

#include <iostream>

// what is a copy constructor? when is it used?

// see the example below
// A copy constructor is a construcor which fist parameter is a `reference`
// such as `explicit T(T &i, char c_='0', double d_=0.1);` and any additional
// parameters have `default values`

// when to use? refer to 'github.com/Mooophy/Cpp-Primer/tree/master/ch13'

class T
{
        private:
                int n;
                char c;
                double d;
        public:
                explicit T() { n = 1; c = 'a'; d = 0.309; }
                explicit T(T &i, char c_='0', double d_=0.1);
                explicit T(int n_) : n(n_), c('c'), d(0.92) { std::cout << "copy\n"; };
                T(char c_): n(1), c(c_), d(0.92) { std::cout << "copy\n"; };
                void get();
};

T::T(T &i, char c_, double d_)
{
        if(c_ == '0' && d_ == 0.1)
        {
                n = i.n;
                c = 'b';
                d = 0.2;
        }
        else
        {
                n = 0;
                c = i.c;
                d = i.d;
        }
        std::cout << "copy obj\n";
}

inline void T::get()
{
        std::cout << n << " " << c << " " << d << std::endl;
}

int main()
{
        T a;

        T b(a);

        b.get();

        a.get();

        T c;

       // c = 10;         // cause `explicit` keyword at `T(int n_)`
       c = 'c';

        return 0;
}
